package com.cipe.cmrs.model;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.annotations.Type;
import org.springframework.util.AutoPopulatingList;

import com.cipe.cmrs.bean.PaymentRequestLineItemBean;
import com.cipe.cmrs.util.NumberUtil;

/**
 * <p>
 * Pojo mapping TABLE dbo.PaymentRequest
 * </p>
 * 
 * <p>
 * Generated at Sat Dec 03 14:39:47 PKT 2011
 * </p>
 * 
 * @author Incepio
 * 
 */
@Entity
@Table(name = "paymentrequest")
@NamedQueries({ @NamedQuery(name = "findPaymentrequest", query = " FROM Paymentrequest pr where pr.paymentIdentifiedInformation = ? and pr.payee.id = ?") })
@SuppressWarnings("serial")
public class Paymentrequest extends BaseAuditEntity {

	@Transient
	String message;
	@Transient
	String prc;
	
	
	/**
	 * Attribute assignedToUser.
	 */
	@Transient
	private String assignedToUser;
	/**
	 * Attribute country
	 */
    @ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "countryid")
	private Country country;
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "dateinfinance")
	private Date dateToFinanace;
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "invoicedate")
	private Date invoiceRequestDate;
	/**
	 * Attribute payee
	 */
    @ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "payeeid")
	private Payee payee;

    @ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "paymenttypeid")
	private Paymenttype paymenttype;
	/**
	 * Attribute FIXME Invoice Number
	 */
	@Basic
	@Column(name = "paymentconfirmationnumber", length = 50)
	private String paymentConfirmationNumber;
	/**
	 * Attribute paymentIdentifiedInformation.
	 */
	@Basic
	@Column(name = "paymentidentifiedinformation", length = 50)
	private String paymentIdentifiedInformation;
	@Transient
	private String costcenternumber;
	/**
	 * List of Paymentlineitem
	 */
	/*
	 * FIXME @OneToMany(mappedBy = "paymentrequest") private
	 * List<Paymentlineitem> paymentlineitems = null;
	 */
	/**
	 * Attribute paymentmethod
	 */

	private String paymentmethod;
	/**
	 * List of Paymentrequestmodification
	 */
	/*
	 * FIXME @OneToMany(mappedBy = "paymentrequest") private
	 * List<Paymentrequestmodification> paymentrequestmodifications = null;
	 */
	/**
	 * List of Paymentrequeststatus
	 */
	@OneToMany(mappedBy = "paymentrequest")
	private List<Paymentrequeststatus> paymentrequeststatuss = null;

	/**
	 * List of paymentrequest
	 */
	@OneToMany(mappedBy = "paymentrequest", cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE })
	private List<Paymentrequestlineitem> paymentrequestlineitems;
	@Transient
	private List<PaymentRequestLineItemBean> lineItemBeans = new AutoPopulatingList<PaymentRequestLineItemBean>(PaymentRequestLineItemBean.class);

	/**
	 * Attribute paymentrequesttype
	 */
	/*
	 * @ManyToOne
	 * 
	 * @JoinColumn(name = "paymentrequesttypeid") private Paymentrequesttype
	 * paymentrequesttype;
	 */
	@Transient
	private AccountCode accountcode;

	/**
	 * List of Paymentwireinfo
	 */
	/*
	 * @OneToMany(mappedBy = "paymentrequest") private List<Paymentwireinfo>
	 * paymentwireinfos = null;
	 */
	/**
	 * Attribute purposeOfExpenditure.
	 */
	@Basic
	@Column(name = "purposeofexpenditure", length = 50)
	private String purposeOfExpenditure;
	/**
	 * Attribute Date Entered FIXME Date Entered
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "receivedfromaccountingdate")
	private Date receivedFromAccountingDate;
	/**
	 * Attribute requestUserId.
	 */
	@Transient
	private Integer requestUserId;
	/**
	 * Attribute specialInstructions.
	 */
	@Basic
	@Column(name = "specialinstructions", length = 100)
	private String specialInstructions;
	/**
	 * Attribute statusCode.
	 */
	@Basic
	@Column(name = "statuscode", length = 30)
	private String statusCode;

	/**
	 * Attribute memonotes.
	 */
	private String memonotes;

	/**
	 * Attribute deliverablesreceived.
	 */
	private Boolean deliverablesreceived;

	/**
	 * Attribute invoicenumber.
	 */
	private String invoicenumber;

	/**
	 * Attribute amount.
	 */
	private BigDecimal amount;

	/**
	 * Attribute paidamount.
	 */
	private BigDecimal paidamount;

	/**
	 * Attribute comments.
	 */
	private String comments;

	/**
	 * Attribute daterejected.
	 */
	@Temporal(TemporalType.TIMESTAMP)
	private Date daterejected;

	@Column(name = "reasonrejected", length = 500)
	private String reasonrejected;

	/**
	 * Attribute dateresubmitted.
	 */
	@Temporal(TemporalType.TIMESTAMP)
	private Date dateresubmitted;

	/**
	 * Attribute dateforwardedforsignature.
	 */
	@Temporal(TemporalType.TIMESTAMP)
	private Date dateforwardedforsignature;

	@Temporal(TemporalType.TIMESTAMP)
	private Date datesubmittedforpayment;

	/**
	 * Attribute pendingpaymentdate.
	 */
	@Temporal(TemporalType.TIMESTAMP)
	private Date pendingpaymentdate;

	/**
	 * Attribute datecancelled.
	 */
	@Temporal(TemporalType.TIMESTAMP)
	private Date datecancelled;

	private String currentlyresponsible;

	@Temporal(TemporalType.TIMESTAMP)
	private Date datepaid;
	// Transient for form backing

	@Transient
	private Date startDate;

	@Transient
	private Date endDate;

	@Transient
	private BigDecimal startAmount;

	@Transient
	private BigDecimal endAmount;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "datecancelrequested")
	private Date dateCancelRequested;
	
    @Column(name = "sourcedocumenttype")
    private String sourceDocumentType;

    @Column(name = "_6570verify")
    @Type(type = "yes_no")
    private Boolean _6570Verify;

    /**
	 * @return assignedToUser
	 */
	public String getAssignedToUser() {
		return assignedToUser;
	}

	/**
	 * get country
	 */
	public Country getCountry() {
		return this.country;
	}

	public Date getDateToFinanace() {
		return dateToFinanace;
	}

	public Date getInvoiceRequestDate() {
		return invoiceRequestDate;
	}

	/**
	 * get payee
	 */
	public Payee getPayee() {
		return this.payee;
	}

	/**
	 * @return paymentConfirmationNumber
	 */
	public String getPaymentConfirmationNumber() {
		return paymentConfirmationNumber;
	}

	/**
	 * @return paymentIdentifiedInformation
	 */
	public String getPaymentIdentifiedInformation() {
		return paymentIdentifiedInformation;
	}

	/**
	 * Get the list of Paymentlineitem
	 */
	/*
	 * public List<Paymentlineitem> getPaymentlineitems() { return
	 * this.paymentlineitems; }
	 */

	/**
	 * get paymentmethod
	 */
	public String getPaymentmethod() {
		return this.paymentmethod;
	}

	/**
	 * Get the list of Paymentrequestmodification
	 */
	/*
	 * public List<Paymentrequestmodification> getPaymentrequestmodifications()
	 * { return this.paymentrequestmodifications; }
	 */

	/**
	 * Get the list of Paymentrequeststatus
	 */
	public List<Paymentrequeststatus> getPaymentrequeststatuss() {
		return this.paymentrequeststatuss;
	}

	/**
	 * Get the list of Paymentwireinfo
	 */
	/*
	 * public List<Paymentwireinfo> getPaymentwireinfos() { return
	 * this.paymentwireinfos; }
	 */

	/**
	 * @return purposeOfExpenditure
	 */
	public String getPurposeOfExpenditure() {
		return purposeOfExpenditure;
	}

	/**
	 * @return receivedFromAccountingDate
	 */
	public Date getReceivedFromAccountingDate() {
		return receivedFromAccountingDate;
	}

	/**
	 * @return requestUserId
	 */
	public Integer getRequestUserId() {
		return requestUserId;
	}

	/**
	 * @return specialInstructions
	 */
	public String getSpecialInstructions() {
		return specialInstructions;
	}

	/**
	 * @return statusCode
	 */
	public String getStatusCode() {
		return statusCode;
	}

	/**
	 * @param assignedToUser
	 *            new value for assignedToUser
	 */
	public void setAssignedToUser(String assignedToUser) {
		this.assignedToUser = assignedToUser;
	}

	/**
	 * set country
	 */
	public void setCountry(Country country) {
		this.country = country;
	}

	public void setDateToFinanace(Date dateToFinanace) {
		this.dateToFinanace = dateToFinanace;
	}

	public void setInvoiceRequestDate(Date invoiceRequestDate) {
		this.invoiceRequestDate = invoiceRequestDate;
	}

	/**
	 * set payee
	 */
	public void setPayee(Payee payee) {
		this.payee = payee;
	}

	/**
	 * @param paymentConfirmationNumber
	 *            new value for paymentConfirmationNumber
	 */
	public void setPaymentConfirmationNumber(String paymentConfirmationNumber) {
		this.paymentConfirmationNumber = paymentConfirmationNumber;
	}

	/**
	 * @param paymentIdentifiedInformation
	 *            new value for paymentIdentifiedInformation
	 */
	public void setPaymentIdentifiedInformation(String paymentIdentifiedInformation) {
		this.paymentIdentifiedInformation = paymentIdentifiedInformation;
	}

	/**
	 * Set the list of Paymentlineitem
	 */
	/*
	 * public void setPaymentlineitems(List<Paymentlineitem> paymentlineitems) {
	 * this.paymentlineitems = paymentlineitems; }
	 */

	/**
	 * set paymentmethod
	 */
	public void setPaymentmethod(String paymentmethod) {
		this.paymentmethod = paymentmethod;
	}

	/**
	 * Set the list of Paymentrequestmodification
	 */
	/*
	 * public void
	 * setPaymentrequestmodifications(List<Paymentrequestmodification>
	 * paymentrequestmodifications) { this.paymentrequestmodifications =
	 * paymentrequestmodifications; }
	 */
	/**
	 * Set the list of Paymentrequeststatus
	 */
	public void setPaymentrequeststatuss(List<Paymentrequeststatus> paymentrequeststatuss) {
		this.paymentrequeststatuss = paymentrequeststatuss;
	}

	/**
	 * Set the list of Paymentwireinfo
	 */
	/*
	 * public void setPaymentwireinfos(List<Paymentwireinfo> paymentwireinfos) {
	 * this.paymentwireinfos = paymentwireinfos; }
	 */

	/**
	 * @param purposeOfExpenditure
	 *            new value for purposeOfExpenditure
	 */
	public void setPurposeOfExpenditure(String purposeOfExpenditure) {
		this.purposeOfExpenditure = purposeOfExpenditure;
	}

	/**
	 * @param receivedFromAccountingDate
	 *            new value for receivedFromAccountingDate
	 */
	public void setReceivedFromAccountingDate(Date receivedFromAccountingDate) {
		this.receivedFromAccountingDate = receivedFromAccountingDate;
	}

	/**
	 * @param requestUserId
	 *            new value for requestUserId
	 */
	public void setRequestUserId(Integer requestUserId) {
		this.requestUserId = requestUserId;
	}

	/**
	 * @param specialInstructions
	 *            new value for specialInstructions
	 */
	public void setSpecialInstructions(String specialInstructions) {
		this.specialInstructions = specialInstructions;
	}

	/**
	 * @param statusCode
	 *            new value for statusCode
	 */
	public void setStatusCode(String statusCode) {
		this.statusCode = statusCode;
	}

	public Paymenttype getPaymenttype() {
		return paymenttype;
	}

	public void setPaymenttype(Paymenttype paymenttype) {
		this.paymenttype = paymenttype;
	}

	public String getMemonotes() {
		return memonotes;
	}

	public void setMemonotes(String memonotes) {
		this.memonotes = memonotes;
	}

	public Boolean getDeliverablesreceived() {
		return deliverablesreceived;
	}

	public void setDeliverablesreceived(Boolean deliverablesreceived) {
		this.deliverablesreceived = deliverablesreceived;
	}

	public String getInvoicenumber() {
		return invoicenumber;
	}

	public void setInvoicenumber(String invoicenumber) {
		this.invoicenumber = invoicenumber;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public BigDecimal getPaidamount() {
		return paidamount;
	}

	public void setPaidamount(BigDecimal paidamount) {
		this.paidamount = paidamount;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public Date getDaterejected() {
		return daterejected;
	}

	public void setDaterejected(Date daterejected) {
		this.daterejected = daterejected;
	}

	public String getReasonrejected() {
		return reasonrejected;
	}

	public void setReasonrejected(String reasonrejected) {
		this.reasonrejected = reasonrejected;
	}

	public Date getDateresubmitted() {
		return dateresubmitted;
	}

	public void setDateresubmitted(Date dateresubmitted) {
		this.dateresubmitted = dateresubmitted;
	}

	public Date getDateforwardedforsignature() {
		return dateforwardedforsignature;
	}

	public void setDateforwardedforsignature(Date dateforwardedforsignature) {
		this.dateforwardedforsignature = dateforwardedforsignature;
	}

	public Date getPendingpaymentdate() {
		return pendingpaymentdate;
	}

	public void setPendingpaymentdate(Date pendingpaymentdate) {
		this.pendingpaymentdate = pendingpaymentdate;
	}

	public Date getDatecancelled() {
		return datecancelled;
	}

	public void setDatecancelled(Date datecancelled) {
		this.datecancelled = datecancelled;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public BigDecimal getStartAmount() {
		return startAmount;
	}

	public void setStartAmount(BigDecimal startAmount) {
		this.startAmount = startAmount;
	}

	public BigDecimal getEndAmount() {
		return endAmount;
	}

	public void setEndAmount(BigDecimal endAmount) {
		this.endAmount = endAmount;
	}

	public AccountCode getAccountcode() {
		return accountcode;
	}

	public void setAccountcode(AccountCode accountcode) {
		this.accountcode = accountcode;
	}

	public String getCostcenternumber() {
		return costcenternumber;
	}

	public void setCostcenternumber(String costcenternumber) {
		this.costcenternumber = costcenternumber;
	}

	public List<Paymentrequestlineitem> getPaymentrequestlineitems() {
		return paymentrequestlineitems;
	}

	public void setPaymentrequestlineitems(List<Paymentrequestlineitem> paymentrequestlineitems) {
		this.paymentrequestlineitems = paymentrequestlineitems;
	}

	public String getCurrentlyresponsible() {
		return currentlyresponsible;
	}

	public void setCurrentlyresponsible(String currentlyresponsible) {
		this.currentlyresponsible = currentlyresponsible;
	}

	public Date getDatesubmittedforpayment() {
		return datesubmittedforpayment;
	}

	public void setDatesubmittedforpayment(Date datesubmittedforpayment) {
		this.datesubmittedforpayment = datesubmittedforpayment;
	}

	public Date getDatepaid() {
		return datepaid;
	}

	public void setDatepaid(Date datepaid) {
		this.datepaid = datepaid;
	}

	public List<PaymentRequestLineItemBean> getLineItemBeans() {
		return lineItemBeans;
	}

	public void setLineItemBeans(List<PaymentRequestLineItemBean> lineItemBeans) {
		this.lineItemBeans = lineItemBeans;
	}

	public Date getDateCancelRequested() {
		return dateCancelRequested;
	}

	public void setDateCancelRequested(Date dateCancelRequested) {
        this.dateCancelRequested = dateCancelRequested;
    }

    public String getSourceDocumentType() {
        return sourceDocumentType;
    }

    public void setSourceDocumentType(String sourceDocumentType) {
        this.sourceDocumentType = sourceDocumentType;
    }

    public Boolean get_6570Verify() {
        return _6570Verify;
    }

    public void set_6570Verify(Boolean _6570Verify) {
        this._6570Verify = _6570Verify;
    }

    /**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * @return the prc
	 */
	public String getPrc() {
		return prc;
	}

	/**
	 * @param prc the prc to set
	 */
	public void setPrc(String prc) {
		this.prc = prc;
	}

	
	@Transient
	private long numberOfDays;
	
   public long getNumberOfDays(){
	   long timeConv = 1000 * 60 * 60 * 24;
	   try{
		   long days =  ((new Date()).getTime()-getCreationDate().getTime()) / timeConv;
		   return days;
		   
	   } catch (Exception e) {
		   e.printStackTrace();
	   }
	   return 0;
    }

    @Override
    public boolean equals(Object object) {
        Paymentrequest target = (Paymentrequest) object;
        return NumberUtil.INSTANCE.isEqual(id, target.getId());
    }
    
    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(super.hashCode()).append(id).toHashCode();
    }
}